from typing import Optional, List
from pydantic import BaseModel, Field
from datetime import datetime


class SystemConfigBase(BaseModel):
    """系统配置基础模型"""
    key: str = Field(..., max_length=100, description="配置键")
    value: str = Field(..., description="配置值")
    description: Optional[str] = Field(None, max_length=255, description="配置描述")
    type: str = Field(default="string", max_length=20, description="配置类型")
    is_system: bool = Field(default=False, description="是否系统配置")
    is_public: bool = Field(default=True, description="是否公开配置")
    remark: Optional[str] = Field(None, description="备注")


class SystemConfigCreate(SystemConfigBase):
    """创建系统配置"""
    pass


class SystemConfigUpdate(BaseModel):
    """更新系统配置"""
    value: Optional[str] = Field(None, description="配置值")
    description: Optional[str] = Field(None, max_length=255, description="配置描述")
    type: Optional[str] = Field(None, max_length=20, description="配置类型")
    is_system: Optional[bool] = Field(None, description="是否系统配置")
    is_public: Optional[bool] = Field(None, description="是否公开配置")
    remark: Optional[str] = Field(None, description="备注")


class SystemConfigResponse(SystemConfigBase):
    """系统配置响应模型"""
    id: int
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True


class SystemConfigListResponse(BaseModel):
    """系统配置列表响应"""
    total: int
    items: List[SystemConfigResponse]


class SystemConfigBatchUpdate(BaseModel):
    """批量更新系统配置"""
    configs: List[dict] = Field(..., description="配置列表，格式：[{'key': 'value'}]")


class SystemConfigImport(BaseModel):
    """系统配置导入"""
    configs: List[SystemConfigBase] = Field(..., description="配置列表")


class SystemConfigExport(BaseModel):
    """系统配置导出"""
    keys: Optional[List[str]] = Field(None, description="要导出的配置键列表，为空则导出所有")
    include_system: bool = Field(default=True, description="是否包含系统配置")
    include_private: bool = Field(default=False, description="是否包含私有配置") 